package com.salary.system;

import java.time.LocalDate;

public class Main {
    public static void main(String[] args) {
        Employee[] employees = {
            new RegularEmployee(
                "张三", "EMP001", "技术部", LocalDate.of(2023, 3, 15),
                28.5, 200
            ),
            new Manager(
                "李四", "MGR001", "财务部", LocalDate.of(2021, 5, 20),
                15000, 3000, 1.2
            ),
            new RegularEmployee(
                "王五", "EMP002", "运营部", LocalDate.of(2024, 1, 10),
                25, 700
            ),
            new Manager(
                "赵六", "MGR002", "市场部", LocalDate.of(2022, 7, 8),
                12000, 2500, 1.0
            )
        };

        String txtFile = "pay_slip.txt";
        for (Employee emp : employees) {
            try {
                String paySlip = emp.generatePaySlip();
                System.out.println(paySlip);
                System.out.println("------------------------------");
                FileUtil.savePaySlip(paySlip, txtFile);
            } catch (InvalidWorkHoursException e) {
                String errorMsg = "【薪资计算失败】" + emp.getName() + "（" + emp.getEmpId() + "）：" + e.getMessage();
                System.out.println(errorMsg);
                System.out.println("------------------------------");
                FileUtil.savePaySlip(errorMsg, txtFile);
            } catch (IllegalParameterException e) {
                String errorMsg = "【参数非法】" + emp.getName() + "（" + emp.getEmpId() + "）：" + e.getMessage();
                System.out.println(errorMsg);
                System.out.println("------------------------------");
                FileUtil.savePaySlip(errorMsg, txtFile);
            }
        }
    }
}